In [1]:
from PIL import Image
In [2]:
bob = Image.open('spongebob.jpeg')
bob
Out[2]:
In [3]:
bob.show()
In [4]:
bob.size
Out[4]:
(640, 399)
In [5]:
bob.format
Out[5]:
'JPEG'
In [6]:
bob.mode
Out[6]:
'RGB'
In [7]:
w, h = bob.size
In [8]:
w*h
Out[8]:
255360
In [9]:
bob.convert('L')
Out[9]:
In [10]:
bob.convert('1')
Out[10]:
In [11]:
plankton = Image.open('plankton.jpg')
plankton
Out[11]:
In [12]:
bob
Out[12]:
In [13]:
crop_box = ( 180, 80, 500, 390 )
In [14]:
bob_face = bob.crop(crop_box)
In [15]:
bob_face.save('face.jpg')
In [16]:
bob.resize(( 320, 100 ))
Out[16]:
In [17]:
small_img = bob.resize(( w//2, h//2 ))
small_img
Out[17]:
In [18]:
small_img.resize((w*3, h*3))
Out[18]:
In [19]:
plankton2 = Image.open('plankton2.jpg')
In [20]:
plankton2 = plankton2.resize((w, h))
In [21]:
Image.blend(bob, plankton2, 0.8)
Out[21]:
In [22]:
bob.rotate(20)
Out[22]:
In [23]:
bob.transpose(Image.ROTATE_90)
Out[23]:
In [24]:
bob.transpose(Image.FLIP_LEFT_RIGHT)
Out[24]:
In [25]:
bob.transpose(Image.FLIP_TOP_BOTTOM)
Out[25]:
In [26]:
Image.blend(bob, bob.transpose(Image.FLIP_TOP_BOTTOM), 0.4)
Out[26]:
In [27]:
from PIL import ImageFilter
In [28]:
bob.filter(ImageFilter.BLUR)
Out[28]:
In [29]:
blurred = bob.filter(ImageFilter.BoxBlur(5))
blurred
Out[29]:
In [30]:
bob.filter(ImageFilter.DETAIL)
Out[30]:
In [31]:
bob.filter(ImageFilter.EMBOSS)
Out[31]:
In [32]:
bob.filter(ImageFilter.FIND_EDGES)
Out[32]:
In [33]:
bob.filter(ImageFilter.SHARPEN)
Out[33]:
In [34]:
bob.filter(ImageFilter.CONTOUR)
Out[34]:
In [35]:
ex_img = blurred
for i in range(5):
    ex_img = ex_img.filter(ImageFilter.SHARPEN)
In [36]:
ex_img
Out[36]:
In [37]:
bob.thumbnail((100, 100))
In [38]:
bob
Out[38]:
In [39]:
import os
In [40]:
images_path = []
for f in os.listdir('C:\Summer Training\DP_PYDS_500\image_processing'):
    if f.endswith('.jpg'):
        images_path.append('C:\Summer Training\DP_PYDS_500\image_processing\\'+f)
In [41]:
images_path
Out[41]:
['C:\\Summer Training\\DP_PYDS_500\\image_processing\\face.jpg',
 'C:\\Summer Training\\DP_PYDS_500\\image_processing\\plankton.jpg',
 'C:\\Summer Training\\DP_PYDS_500\\image_processing\\plankton2.jpg']
In [42]:
# WAP to create and save thumbnail of images in a given folder
In [ ]: